{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "37a87645",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from tqdm import tqdm\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "from PIL import Image\n",
    "\n",
    "import torch\n",
    "import torch.nn.functional as F"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ef0ab0ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "device cuda:0\n"
     ]
    }
   ],
   "source": [
    "# 有 GPU 就用 GPU，没有就用 CPU\n",
    "device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\n",
    "print('device', device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "53fb05a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torchvision import transforms\n",
    "\n",
    "# 训练集图像预处理：缩放裁剪、图像增强、转 Tensor、归一化\n",
    "train_transform = transforms.Compose([transforms.RandomResizedCrop(224),\n",
    "                                      transforms.RandomHorizontalFlip(),\n",
    "                                      transforms.ToTensor(),\n",
    "                                      transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])\n",
    "                                     ])\n",
    "\n",
    "# 测试集图像预处理-RCTN：缩放、裁剪、转 Tensor、归一化\n",
    "test_transform = transforms.Compose([transforms.Resize(256),\n",
    "                                     transforms.CenterCrop(224),\n",
    "                                     transforms.ToTensor(),\n",
    "                                     transforms.Normalize(\n",
    "                                         mean=[0.485, 0.456, 0.406], \n",
    "                                         std=[0.229, 0.224, 0.225])\n",
    "                                    ])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2769b48b",
   "metadata": {},
   "source": [
    "# 载入测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a50944e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_dir = 'melon17_split'\n",
    "test_path = os.path.join(dataset_dir, 'val')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1448bbda",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torchvision import datasets\n",
    "\n",
    "# 载入测试集\n",
    "test_dataset = datasets.ImageFolder(test_path, test_transform)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "77e6e636",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集图像数量 509\n",
      "类别个数 17\n",
      "各类别名称 ['丝瓜', '人参果', '佛手瓜', '冬瓜', '南瓜', '哈密瓜', '木瓜', '甜瓜-伊丽莎白', '甜瓜-白', '甜瓜-绿', '甜瓜-金', '白兰瓜', '羊角蜜', '苦瓜', '西瓜', '西葫芦', '黄瓜']\n"
     ]
    }
   ],
   "source": [
    "print('训练集图像数量', len(test_dataset))\n",
    "print('类别个数', len(test_dataset.classes))\n",
    "print('各类别名称', test_dataset.classes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a47c89c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class_names = test_dataset.classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "14f1aa34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'丝瓜': 0,\n",
       " '人参果': 1,\n",
       " '佛手瓜': 2,\n",
       " '冬瓜': 3,\n",
       " '南瓜': 4,\n",
       " '哈密瓜': 5,\n",
       " '木瓜': 6,\n",
       " '甜瓜-伊丽莎白': 7,\n",
       " '甜瓜-白': 8,\n",
       " '甜瓜-绿': 9,\n",
       " '甜瓜-金': 10,\n",
       " '白兰瓜': 11,\n",
       " '羊角蜜': 12,\n",
       " '苦瓜': 13,\n",
       " '西瓜': 14,\n",
       " '西葫芦': 15,\n",
       " '黄瓜': 16}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 映射关系：类别 到 索引号\n",
    "test_dataset.class_to_idx"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53e221f8",
   "metadata": {},
   "source": [
    "# 载入类别名称和ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "824a915e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: '丝瓜',\n",
       " 1: '人参果',\n",
       " 2: '佛手瓜',\n",
       " 3: '冬瓜',\n",
       " 4: '南瓜',\n",
       " 5: '哈密瓜',\n",
       " 6: '木瓜',\n",
       " 7: '甜瓜-伊丽莎白',\n",
       " 8: '甜瓜-白',\n",
       " 9: '甜瓜-绿',\n",
       " 10: '甜瓜-金',\n",
       " 11: '白兰瓜',\n",
       " 12: '羊角蜜',\n",
       " 13: '苦瓜',\n",
       " 14: '西瓜',\n",
       " 15: '西葫芦',\n",
       " 16: '黄瓜'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "idx_to_labels = np.load('idx_to_labels.npy', allow_pickle=True).item()\n",
    "idx_to_labels\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "221c4b2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['丝瓜', '人参果', '佛手瓜', '冬瓜', '南瓜', '哈密瓜', '木瓜', '甜瓜-伊丽莎白', '甜瓜-白', '甜瓜-绿', '甜瓜-金', '白兰瓜', '羊角蜜', '苦瓜', '西瓜', '西葫芦', '黄瓜']\n"
     ]
    }
   ],
   "source": [
    "classes = list(idx_to_labels.values())\n",
    "print(classes)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8a67144",
   "metadata": {},
   "source": [
    "# 测试集图像路径以及标注\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "de4fa335",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('melon17_split\\\\val\\\\丝瓜\\\\109.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\111.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\113.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\115.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\120.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\135.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\141.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\143.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\150.jpg', 0),\n",
       " ('melon17_split\\\\val\\\\丝瓜\\\\160.jpg', 0)]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_dataset.imgs[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "58b0d6e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "img_paths = [each[0] for each in test_dataset.imgs]\n",
    "df = pd.DataFrame()\n",
    "df['图像路径'] = img_paths\n",
    "df['标注类别ID'] = test_dataset.targets\n",
    "df['标注类别名称'] = [idx_to_labels[ID] for ID in test_dataset.targets]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "35b415df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>图像路径</th>\n",
       "      <th>标注类别ID</th>\n",
       "      <th>标注类别名称</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\109.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\111.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\113.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\115.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\120.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>504</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\85.jpeg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>505</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\91.png</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>506</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\92.jpg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>507</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\96.png</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>508</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\97.jpg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>509 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             图像路径  标注类别ID 标注类别名称\n",
       "0    melon17_split\\val\\丝瓜\\109.jpg       0     丝瓜\n",
       "1    melon17_split\\val\\丝瓜\\111.jpg       0     丝瓜\n",
       "2    melon17_split\\val\\丝瓜\\113.jpg       0     丝瓜\n",
       "3    melon17_split\\val\\丝瓜\\115.jpg       0     丝瓜\n",
       "4    melon17_split\\val\\丝瓜\\120.jpg       0     丝瓜\n",
       "..                            ...     ...    ...\n",
       "504  melon17_split\\val\\黄瓜\\85.jpeg      16     黄瓜\n",
       "505   melon17_split\\val\\黄瓜\\91.png      16     黄瓜\n",
       "506   melon17_split\\val\\黄瓜\\92.jpg      16     黄瓜\n",
       "507   melon17_split\\val\\黄瓜\\96.png      16     黄瓜\n",
       "508   melon17_split\\val\\黄瓜\\97.jpg      16     黄瓜\n",
       "\n",
       "[509 rows x 3 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "eca30cfa",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = torch.load('checkpoints/melon17_pytorch_20220812.pth')\n",
    "model = model.eval().to(device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "41bc9904",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "509it [00:40, 12.72it/s]\n"
     ]
    }
   ],
   "source": [
    "n=3\n",
    "df_pred = pd.DataFrame()\n",
    "for idx, row in tqdm(df.iterrows()):\n",
    "    img_path = row['图像路径']\n",
    "    img_pil = Image.open(img_path).convert('RGB')\n",
    "    input_img = test_transform(img_pil).unsqueeze(0).to(device) # 预处理\n",
    "    pred_logits = model(input_img) # 执行前向预测，得到所有类别的 logit 预测分数\n",
    "    pred_softmax = F.softmax(pred_logits, dim=1) # 对 logit 分数做 softmax 运算\n",
    "\n",
    "    pred_dict = {}\n",
    "\n",
    "    top_n = torch.topk(pred_softmax, n) # 取置信度最大的 n 个结果\n",
    "    pred_ids = top_n[1].cpu().detach().numpy().squeeze() # 解析出类别\n",
    "    \n",
    "    # top-n 预测结果\n",
    "    for i in range(1, n+1):\n",
    "        pred_dict['top-{}-预测ID'.format(i)] = pred_ids[i-1]\n",
    "        pred_dict['top-{}-预测名称'.format(i)] = idx_to_labels[pred_ids[i-1]]\n",
    "    pred_dict['top-n预测正确'] = row['标注类别ID'] in pred_ids\n",
    "    # 每个类别的预测置信度\n",
    "    for idx, each in enumerate(classes):\n",
    "        pred_dict['{}-预测置信度'.format(each)] = pred_softmax[0][idx].cpu().detach().numpy()\n",
    "        \n",
    "    df_pred = df_pred.append(pred_dict, ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5315068c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>top-1-预测ID</th>\n",
       "      <th>top-1-预测名称</th>\n",
       "      <th>top-2-预测ID</th>\n",
       "      <th>top-2-预测名称</th>\n",
       "      <th>top-3-预测ID</th>\n",
       "      <th>top-3-预测名称</th>\n",
       "      <th>top-n预测正确</th>\n",
       "      <th>丝瓜-预测置信度</th>\n",
       "      <th>人参果-预测置信度</th>\n",
       "      <th>佛手瓜-预测置信度</th>\n",
       "      <th>...</th>\n",
       "      <th>甜瓜-伊丽莎白-预测置信度</th>\n",
       "      <th>甜瓜-白-预测置信度</th>\n",
       "      <th>甜瓜-绿-预测置信度</th>\n",
       "      <th>甜瓜-金-预测置信度</th>\n",
       "      <th>白兰瓜-预测置信度</th>\n",
       "      <th>羊角蜜-预测置信度</th>\n",
       "      <th>苦瓜-预测置信度</th>\n",
       "      <th>西瓜-预测置信度</th>\n",
       "      <th>西葫芦-预测置信度</th>\n",
       "      <th>黄瓜-预测置信度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>2.0</td>\n",
       "      <td>佛手瓜</td>\n",
       "      <td>12.0</td>\n",
       "      <td>羊角蜜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.35024515</td>\n",
       "      <td>0.0037912591</td>\n",
       "      <td>0.3132659</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0024468428</td>\n",
       "      <td>0.03495915</td>\n",
       "      <td>0.008615349</td>\n",
       "      <td>0.006597194</td>\n",
       "      <td>0.006824426</td>\n",
       "      <td>0.18515387</td>\n",
       "      <td>0.0045968834</td>\n",
       "      <td>0.006041198</td>\n",
       "      <td>0.0018484683</td>\n",
       "      <td>0.0021700992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.38743395</td>\n",
       "      <td>0.002061087</td>\n",
       "      <td>0.013266849</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00013219888</td>\n",
       "      <td>0.0008361966</td>\n",
       "      <td>0.0010132068</td>\n",
       "      <td>0.00059327745</td>\n",
       "      <td>0.00022680659</td>\n",
       "      <td>0.0654279</td>\n",
       "      <td>0.27193028</td>\n",
       "      <td>0.00052623084</td>\n",
       "      <td>0.084348455</td>\n",
       "      <td>0.103622615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>3.0</td>\n",
       "      <td>冬瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.39373407</td>\n",
       "      <td>0.0025604665</td>\n",
       "      <td>0.006773903</td>\n",
       "      <td>...</td>\n",
       "      <td>0.016111165</td>\n",
       "      <td>0.030245304</td>\n",
       "      <td>0.0032594402</td>\n",
       "      <td>0.006405023</td>\n",
       "      <td>0.10206279</td>\n",
       "      <td>0.021708922</td>\n",
       "      <td>0.013332135</td>\n",
       "      <td>0.015433673</td>\n",
       "      <td>0.11358579</td>\n",
       "      <td>0.039983284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3.0</td>\n",
       "      <td>冬瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.2682445</td>\n",
       "      <td>0.00044873063</td>\n",
       "      <td>0.0012310648</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0005957154</td>\n",
       "      <td>0.0033406352</td>\n",
       "      <td>0.0022859466</td>\n",
       "      <td>0.00060059415</td>\n",
       "      <td>0.008349295</td>\n",
       "      <td>0.0032741006</td>\n",
       "      <td>0.019815378</td>\n",
       "      <td>0.0032377015</td>\n",
       "      <td>0.12200484</td>\n",
       "      <td>0.014645959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.41188484</td>\n",
       "      <td>0.0005419592</td>\n",
       "      <td>0.0011034731</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0019108373</td>\n",
       "      <td>0.0003307907</td>\n",
       "      <td>0.00040253712</td>\n",
       "      <td>0.0048545892</td>\n",
       "      <td>0.0007020486</td>\n",
       "      <td>0.0140756965</td>\n",
       "      <td>0.083256386</td>\n",
       "      <td>0.00087326166</td>\n",
       "      <td>0.29723677</td>\n",
       "      <td>0.08933148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>504</th>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.39965254</td>\n",
       "      <td>0.010815328</td>\n",
       "      <td>0.023665033</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0011869364</td>\n",
       "      <td>0.005493155</td>\n",
       "      <td>0.002704433</td>\n",
       "      <td>0.002307347</td>\n",
       "      <td>0.003773076</td>\n",
       "      <td>0.04376564</td>\n",
       "      <td>0.09831918</td>\n",
       "      <td>0.074131615</td>\n",
       "      <td>0.010605056</td>\n",
       "      <td>0.26034984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>505</th>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.009814152</td>\n",
       "      <td>0.0026711235</td>\n",
       "      <td>0.0030488246</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00018131446</td>\n",
       "      <td>0.000850996</td>\n",
       "      <td>0.0005965597</td>\n",
       "      <td>0.00074592454</td>\n",
       "      <td>0.000641472</td>\n",
       "      <td>0.005948413</td>\n",
       "      <td>0.08006687</td>\n",
       "      <td>0.00017836424</td>\n",
       "      <td>0.0009635846</td>\n",
       "      <td>0.8796355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>506</th>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.07409313</td>\n",
       "      <td>0.00015053719</td>\n",
       "      <td>0.000694671</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0001503303</td>\n",
       "      <td>0.0002207423</td>\n",
       "      <td>7.163924e-05</td>\n",
       "      <td>0.00029438158</td>\n",
       "      <td>0.00015897394</td>\n",
       "      <td>0.0021520182</td>\n",
       "      <td>0.0010529484</td>\n",
       "      <td>0.00076220394</td>\n",
       "      <td>0.43672562</td>\n",
       "      <td>0.46046394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>507</th>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.016515005</td>\n",
       "      <td>0.00036248268</td>\n",
       "      <td>0.00012770676</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00010513561</td>\n",
       "      <td>0.00011894954</td>\n",
       "      <td>8.8522414e-05</td>\n",
       "      <td>0.00022187272</td>\n",
       "      <td>0.00033309328</td>\n",
       "      <td>0.00220814</td>\n",
       "      <td>0.068183675</td>\n",
       "      <td>0.00037849342</td>\n",
       "      <td>0.0013618008</td>\n",
       "      <td>0.9066161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>508</th>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>12.0</td>\n",
       "      <td>羊角蜜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.008931217</td>\n",
       "      <td>0.0011941125</td>\n",
       "      <td>0.0021149411</td>\n",
       "      <td>...</td>\n",
       "      <td>9.982722e-06</td>\n",
       "      <td>8.059318e-05</td>\n",
       "      <td>0.00030753392</td>\n",
       "      <td>9.23305e-05</td>\n",
       "      <td>3.4258566e-05</td>\n",
       "      <td>0.023541698</td>\n",
       "      <td>0.1404117</td>\n",
       "      <td>0.006683522</td>\n",
       "      <td>0.004026901</td>\n",
       "      <td>0.80798274</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>509 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     top-1-预测ID top-1-预测名称  top-2-预测ID top-2-预测名称  top-3-预测ID top-3-预测名称  \\\n",
       "0           0.0         丝瓜         2.0        佛手瓜        12.0        羊角蜜   \n",
       "1           0.0         丝瓜        13.0         苦瓜        16.0         黄瓜   \n",
       "2           0.0         丝瓜         3.0         冬瓜        15.0        西葫芦   \n",
       "3           3.0         冬瓜         0.0         丝瓜        15.0        西葫芦   \n",
       "4           0.0         丝瓜        15.0        西葫芦        16.0         黄瓜   \n",
       "..          ...        ...         ...        ...         ...        ...   \n",
       "504         0.0         丝瓜        16.0         黄瓜        13.0         苦瓜   \n",
       "505        16.0         黄瓜        13.0         苦瓜         0.0         丝瓜   \n",
       "506        16.0         黄瓜        15.0        西葫芦         0.0         丝瓜   \n",
       "507        16.0         黄瓜        13.0         苦瓜         0.0         丝瓜   \n",
       "508        16.0         黄瓜        13.0         苦瓜        12.0        羊角蜜   \n",
       "\n",
       "     top-n预测正确     丝瓜-预测置信度      人参果-预测置信度      佛手瓜-预测置信度  ...  甜瓜-伊丽莎白-预测置信度  \\\n",
       "0          1.0   0.35024515   0.0037912591      0.3132659  ...   0.0024468428   \n",
       "1          1.0   0.38743395    0.002061087    0.013266849  ...  0.00013219888   \n",
       "2          1.0   0.39373407   0.0025604665    0.006773903  ...    0.016111165   \n",
       "3          1.0    0.2682445  0.00044873063   0.0012310648  ...   0.0005957154   \n",
       "4          1.0   0.41188484   0.0005419592   0.0011034731  ...   0.0019108373   \n",
       "..         ...          ...            ...            ...  ...            ...   \n",
       "504        1.0   0.39965254    0.010815328    0.023665033  ...   0.0011869364   \n",
       "505        1.0  0.009814152   0.0026711235   0.0030488246  ...  0.00018131446   \n",
       "506        1.0   0.07409313  0.00015053719    0.000694671  ...   0.0001503303   \n",
       "507        1.0  0.016515005  0.00036248268  0.00012770676  ...  0.00010513561   \n",
       "508        1.0  0.008931217   0.0011941125   0.0021149411  ...   9.982722e-06   \n",
       "\n",
       "        甜瓜-白-预测置信度     甜瓜-绿-预测置信度     甜瓜-金-预测置信度      白兰瓜-预测置信度     羊角蜜-预测置信度  \\\n",
       "0       0.03495915    0.008615349    0.006597194    0.006824426    0.18515387   \n",
       "1     0.0008361966   0.0010132068  0.00059327745  0.00022680659     0.0654279   \n",
       "2      0.030245304   0.0032594402    0.006405023     0.10206279   0.021708922   \n",
       "3     0.0033406352   0.0022859466  0.00060059415    0.008349295  0.0032741006   \n",
       "4     0.0003307907  0.00040253712   0.0048545892   0.0007020486  0.0140756965   \n",
       "..             ...            ...            ...            ...           ...   \n",
       "504    0.005493155    0.002704433    0.002307347    0.003773076    0.04376564   \n",
       "505    0.000850996   0.0005965597  0.00074592454    0.000641472   0.005948413   \n",
       "506   0.0002207423   7.163924e-05  0.00029438158  0.00015897394  0.0021520182   \n",
       "507  0.00011894954  8.8522414e-05  0.00022187272  0.00033309328    0.00220814   \n",
       "508   8.059318e-05  0.00030753392    9.23305e-05  3.4258566e-05   0.023541698   \n",
       "\n",
       "         苦瓜-预测置信度       西瓜-预测置信度     西葫芦-预测置信度      黄瓜-预测置信度  \n",
       "0    0.0045968834    0.006041198  0.0018484683  0.0021700992  \n",
       "1      0.27193028  0.00052623084   0.084348455   0.103622615  \n",
       "2     0.013332135    0.015433673    0.11358579   0.039983284  \n",
       "3     0.019815378   0.0032377015    0.12200484   0.014645959  \n",
       "4     0.083256386  0.00087326166    0.29723677    0.08933148  \n",
       "..            ...            ...           ...           ...  \n",
       "504    0.09831918    0.074131615   0.010605056    0.26034984  \n",
       "505    0.08006687  0.00017836424  0.0009635846     0.8796355  \n",
       "506  0.0010529484  0.00076220394    0.43672562    0.46046394  \n",
       "507   0.068183675  0.00037849342  0.0013618008     0.9066161  \n",
       "508     0.1404117    0.006683522   0.004026901    0.80798274  \n",
       "\n",
       "[509 rows x 24 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7442a3ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.concat([df, df_pred], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8f05135f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>图像路径</th>\n",
       "      <th>标注类别ID</th>\n",
       "      <th>标注类别名称</th>\n",
       "      <th>top-1-预测ID</th>\n",
       "      <th>top-1-预测名称</th>\n",
       "      <th>top-2-预测ID</th>\n",
       "      <th>top-2-预测名称</th>\n",
       "      <th>top-3-预测ID</th>\n",
       "      <th>top-3-预测名称</th>\n",
       "      <th>top-n预测正确</th>\n",
       "      <th>...</th>\n",
       "      <th>甜瓜-伊丽莎白-预测置信度</th>\n",
       "      <th>甜瓜-白-预测置信度</th>\n",
       "      <th>甜瓜-绿-预测置信度</th>\n",
       "      <th>甜瓜-金-预测置信度</th>\n",
       "      <th>白兰瓜-预测置信度</th>\n",
       "      <th>羊角蜜-预测置信度</th>\n",
       "      <th>苦瓜-预测置信度</th>\n",
       "      <th>西瓜-预测置信度</th>\n",
       "      <th>西葫芦-预测置信度</th>\n",
       "      <th>黄瓜-预测置信度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\109.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>2.0</td>\n",
       "      <td>佛手瓜</td>\n",
       "      <td>12.0</td>\n",
       "      <td>羊角蜜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0024468428</td>\n",
       "      <td>0.03495915</td>\n",
       "      <td>0.008615349</td>\n",
       "      <td>0.006597194</td>\n",
       "      <td>0.006824426</td>\n",
       "      <td>0.18515387</td>\n",
       "      <td>0.0045968834</td>\n",
       "      <td>0.006041198</td>\n",
       "      <td>0.0018484683</td>\n",
       "      <td>0.0021700992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\111.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00013219888</td>\n",
       "      <td>0.0008361966</td>\n",
       "      <td>0.0010132068</td>\n",
       "      <td>0.00059327745</td>\n",
       "      <td>0.00022680659</td>\n",
       "      <td>0.0654279</td>\n",
       "      <td>0.27193028</td>\n",
       "      <td>0.00052623084</td>\n",
       "      <td>0.084348455</td>\n",
       "      <td>0.103622615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\113.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>3.0</td>\n",
       "      <td>冬瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.016111165</td>\n",
       "      <td>0.030245304</td>\n",
       "      <td>0.0032594402</td>\n",
       "      <td>0.006405023</td>\n",
       "      <td>0.10206279</td>\n",
       "      <td>0.021708922</td>\n",
       "      <td>0.013332135</td>\n",
       "      <td>0.015433673</td>\n",
       "      <td>0.11358579</td>\n",
       "      <td>0.039983284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\115.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>3.0</td>\n",
       "      <td>冬瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0005957154</td>\n",
       "      <td>0.0033406352</td>\n",
       "      <td>0.0022859466</td>\n",
       "      <td>0.00060059415</td>\n",
       "      <td>0.008349295</td>\n",
       "      <td>0.0032741006</td>\n",
       "      <td>0.019815378</td>\n",
       "      <td>0.0032377015</td>\n",
       "      <td>0.12200484</td>\n",
       "      <td>0.014645959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>melon17_split\\val\\丝瓜\\120.jpg</td>\n",
       "      <td>0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0019108373</td>\n",
       "      <td>0.0003307907</td>\n",
       "      <td>0.00040253712</td>\n",
       "      <td>0.0048545892</td>\n",
       "      <td>0.0007020486</td>\n",
       "      <td>0.0140756965</td>\n",
       "      <td>0.083256386</td>\n",
       "      <td>0.00087326166</td>\n",
       "      <td>0.29723677</td>\n",
       "      <td>0.08933148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>504</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\85.jpeg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0011869364</td>\n",
       "      <td>0.005493155</td>\n",
       "      <td>0.002704433</td>\n",
       "      <td>0.002307347</td>\n",
       "      <td>0.003773076</td>\n",
       "      <td>0.04376564</td>\n",
       "      <td>0.09831918</td>\n",
       "      <td>0.074131615</td>\n",
       "      <td>0.010605056</td>\n",
       "      <td>0.26034984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>505</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\91.png</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00018131446</td>\n",
       "      <td>0.000850996</td>\n",
       "      <td>0.0005965597</td>\n",
       "      <td>0.00074592454</td>\n",
       "      <td>0.000641472</td>\n",
       "      <td>0.005948413</td>\n",
       "      <td>0.08006687</td>\n",
       "      <td>0.00017836424</td>\n",
       "      <td>0.0009635846</td>\n",
       "      <td>0.8796355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>506</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\92.jpg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>15.0</td>\n",
       "      <td>西葫芦</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0001503303</td>\n",
       "      <td>0.0002207423</td>\n",
       "      <td>7.163924e-05</td>\n",
       "      <td>0.00029438158</td>\n",
       "      <td>0.00015897394</td>\n",
       "      <td>0.0021520182</td>\n",
       "      <td>0.0010529484</td>\n",
       "      <td>0.00076220394</td>\n",
       "      <td>0.43672562</td>\n",
       "      <td>0.46046394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>507</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\96.png</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>0.0</td>\n",
       "      <td>丝瓜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.00010513561</td>\n",
       "      <td>0.00011894954</td>\n",
       "      <td>8.8522414e-05</td>\n",
       "      <td>0.00022187272</td>\n",
       "      <td>0.00033309328</td>\n",
       "      <td>0.00220814</td>\n",
       "      <td>0.068183675</td>\n",
       "      <td>0.00037849342</td>\n",
       "      <td>0.0013618008</td>\n",
       "      <td>0.9066161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>508</th>\n",
       "      <td>melon17_split\\val\\黄瓜\\97.jpg</td>\n",
       "      <td>16</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>16.0</td>\n",
       "      <td>黄瓜</td>\n",
       "      <td>13.0</td>\n",
       "      <td>苦瓜</td>\n",
       "      <td>12.0</td>\n",
       "      <td>羊角蜜</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>9.982722e-06</td>\n",
       "      <td>8.059318e-05</td>\n",
       "      <td>0.00030753392</td>\n",
       "      <td>9.23305e-05</td>\n",
       "      <td>3.4258566e-05</td>\n",
       "      <td>0.023541698</td>\n",
       "      <td>0.1404117</td>\n",
       "      <td>0.006683522</td>\n",
       "      <td>0.004026901</td>\n",
       "      <td>0.80798274</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>509 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             图像路径  标注类别ID 标注类别名称  top-1-预测ID top-1-预测名称  \\\n",
       "0    melon17_split\\val\\丝瓜\\109.jpg       0     丝瓜         0.0         丝瓜   \n",
       "1    melon17_split\\val\\丝瓜\\111.jpg       0     丝瓜         0.0         丝瓜   \n",
       "2    melon17_split\\val\\丝瓜\\113.jpg       0     丝瓜         0.0         丝瓜   \n",
       "3    melon17_split\\val\\丝瓜\\115.jpg       0     丝瓜         3.0         冬瓜   \n",
       "4    melon17_split\\val\\丝瓜\\120.jpg       0     丝瓜         0.0         丝瓜   \n",
       "..                            ...     ...    ...         ...        ...   \n",
       "504  melon17_split\\val\\黄瓜\\85.jpeg      16     黄瓜         0.0         丝瓜   \n",
       "505   melon17_split\\val\\黄瓜\\91.png      16     黄瓜        16.0         黄瓜   \n",
       "506   melon17_split\\val\\黄瓜\\92.jpg      16     黄瓜        16.0         黄瓜   \n",
       "507   melon17_split\\val\\黄瓜\\96.png      16     黄瓜        16.0         黄瓜   \n",
       "508   melon17_split\\val\\黄瓜\\97.jpg      16     黄瓜        16.0         黄瓜   \n",
       "\n",
       "     top-2-预测ID top-2-预测名称  top-3-预测ID top-3-预测名称  top-n预测正确  ...  \\\n",
       "0           2.0        佛手瓜        12.0        羊角蜜        1.0  ...   \n",
       "1          13.0         苦瓜        16.0         黄瓜        1.0  ...   \n",
       "2           3.0         冬瓜        15.0        西葫芦        1.0  ...   \n",
       "3           0.0         丝瓜        15.0        西葫芦        1.0  ...   \n",
       "4          15.0        西葫芦        16.0         黄瓜        1.0  ...   \n",
       "..          ...        ...         ...        ...        ...  ...   \n",
       "504        16.0         黄瓜        13.0         苦瓜        1.0  ...   \n",
       "505        13.0         苦瓜         0.0         丝瓜        1.0  ...   \n",
       "506        15.0        西葫芦         0.0         丝瓜        1.0  ...   \n",
       "507        13.0         苦瓜         0.0         丝瓜        1.0  ...   \n",
       "508        13.0         苦瓜        12.0        羊角蜜        1.0  ...   \n",
       "\n",
       "     甜瓜-伊丽莎白-预测置信度     甜瓜-白-预测置信度     甜瓜-绿-预测置信度     甜瓜-金-预测置信度  \\\n",
       "0     0.0024468428     0.03495915    0.008615349    0.006597194   \n",
       "1    0.00013219888   0.0008361966   0.0010132068  0.00059327745   \n",
       "2      0.016111165    0.030245304   0.0032594402    0.006405023   \n",
       "3     0.0005957154   0.0033406352   0.0022859466  0.00060059415   \n",
       "4     0.0019108373   0.0003307907  0.00040253712   0.0048545892   \n",
       "..             ...            ...            ...            ...   \n",
       "504   0.0011869364    0.005493155    0.002704433    0.002307347   \n",
       "505  0.00018131446    0.000850996   0.0005965597  0.00074592454   \n",
       "506   0.0001503303   0.0002207423   7.163924e-05  0.00029438158   \n",
       "507  0.00010513561  0.00011894954  8.8522414e-05  0.00022187272   \n",
       "508   9.982722e-06   8.059318e-05  0.00030753392    9.23305e-05   \n",
       "\n",
       "         白兰瓜-预测置信度     羊角蜜-预测置信度      苦瓜-预测置信度       西瓜-预测置信度     西葫芦-预测置信度  \\\n",
       "0      0.006824426    0.18515387  0.0045968834    0.006041198  0.0018484683   \n",
       "1    0.00022680659     0.0654279    0.27193028  0.00052623084   0.084348455   \n",
       "2       0.10206279   0.021708922   0.013332135    0.015433673    0.11358579   \n",
       "3      0.008349295  0.0032741006   0.019815378   0.0032377015    0.12200484   \n",
       "4     0.0007020486  0.0140756965   0.083256386  0.00087326166    0.29723677   \n",
       "..             ...           ...           ...            ...           ...   \n",
       "504    0.003773076    0.04376564    0.09831918    0.074131615   0.010605056   \n",
       "505    0.000641472   0.005948413    0.08006687  0.00017836424  0.0009635846   \n",
       "506  0.00015897394  0.0021520182  0.0010529484  0.00076220394    0.43672562   \n",
       "507  0.00033309328    0.00220814   0.068183675  0.00037849342  0.0013618008   \n",
       "508  3.4258566e-05   0.023541698     0.1404117    0.006683522   0.004026901   \n",
       "\n",
       "         黄瓜-预测置信度  \n",
       "0    0.0021700992  \n",
       "1     0.103622615  \n",
       "2     0.039983284  \n",
       "3     0.014645959  \n",
       "4      0.08933148  \n",
       "..            ...  \n",
       "504    0.26034984  \n",
       "505     0.8796355  \n",
       "506    0.46046394  \n",
       "507     0.9066161  \n",
       "508    0.80798274  \n",
       "\n",
       "[509 rows x 27 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "68fe8111",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('测试集预测结果.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd6668d7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
